import bobingService from '@/api/bobing-api.js'
import {
Dialog,
Button,
NoticeBar,
Popup,
Cell,
CellGroup,
Toast,
Field,
PullRefresh,
List,
Tag,
NavBar,
Image as VanImage,
Sticky
} from 'vant';
export default {
    name: 'Rank',
    components: {
        [Dialog.name]: Dialog,
        [Button.name]: Button,
        [NoticeBar.name]: NoticeBar,
        [Popup.name]: Popup,
        [Cell.name]: Cell,
        [CellGroup.name]: CellGroup,
        [Toast.name]: Toast,
        [Field.name]: Field,
        [PullRefresh.name]: PullRefresh,
        [List.name]:List,
        [Tag.name]:Tag,
        [VanImage.name]:VanImage,
        [NavBar.name]:NavBar,
        [Sticky.name]:Sticky
    },
    data() {
        return {
            isLoading: false,
            rankList: [],
            finished:false,
            loading: false,
        }
    },
    methods: {
        //返回
        onClickLeft() {
            this.$router.push(
                {
                    path: '/Home',
                })
        },
        //刷新
        onRefresh() {
            this.getRanking()
        },
        onLoad() {
            this.getRanking()
        },
        getRanking(){
            let _this = this
            _this.isLoading = true
            _this.loading = true
            _this.rankList = []
            bobingService.ranking().then(response => {
                if (response) {
                    response.forEach(element => {
                        _this.rankList.push(element)
                    });
                }
                _this.loading = false
                _this.isLoading = false
                _this.finished = true
            }, error => {
                Toast('加载出错')
                _this.isLoading = false
                _this.loading = false
                _this.finished = true
            })
        },
    },
    mounted() {
        this.getRanking();
    },
    watch: {
        '$route.path': function (newVal, oldVal) {
            if (oldVal === '/Home') {
                this.getRanking();
            }
        }
    },
}